package com.ruoyi.project.pms.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.db.pms.domain.PmsGoods;
import com.ruoyi.db.pms.domain.query.PmsGoodsQueryVo;
import com.ruoyi.project.pms.service.PmsGoodsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 商品列表Controller
 *
 * @author ruoyi
 * @date 2020-04-20
 */
@Api(tags="pms管理：商品列表管理")
@RestController
@RequestMapping("/pms/goods")
public class PmsGoodsController extends BaseController
{
    @Autowired
    private PmsGoodsService pmsGoodsService;

    @ApiOperation("查询商品列表列表")
    @PreAuthorize("@ss.hasPermi('pms:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmsGoodsQueryVo pmsGoodsQueryVo)
    {
        startPage();
        List<PmsGoods> list = pmsGoodsService.selectPmsGoodsList(pmsGoodsQueryVo);
        return getDataTable(list);
    }

    @ApiOperation("导出商品列表列表")
    @Log(title = "商品列表", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('pms:goods:export')")
    @GetMapping("/export")
    public AjaxResult export(PmsGoodsQueryVo pmsGoodsQueryVo)
    {
        List<PmsGoods> list = pmsGoodsService.selectPmsGoodsList(pmsGoodsQueryVo);
        ExcelUtil<PmsGoods> util = new ExcelUtil<PmsGoods>(PmsGoods.class);
        return util.exportExcel(list, "goods");
    }

    @ApiOperation("获取商品列表详细信息")
    @Log(title = "商品列表", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('pms:goods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pmsGoodsService.selectPmsGoodsById(id));
    }

    @ApiOperation("新增商品列表")
    @Log(title = "商品列表", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('pms:goods:add')")
    @PostMapping
    public AjaxResult add(@RequestBody PmsGoods pmsGoods)
    {
        return toAjax(pmsGoodsService.insertPmsGoods(pmsGoods));
    }

    @ApiOperation("修改商品列表")
    @Log(title = "商品列表", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('pms:goods:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody PmsGoods pmsGoods)
    {
        return toAjax(pmsGoodsService.updatePmsGoods(pmsGoods));
    }

    @ApiOperation("删除商品列表")
    @Log(title = "商品列表", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('pms:goods:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmsGoodsService.deletePmsGoodsByIds(ids));
    }
}
